<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width">
    <script type="application/javascript" src='https://lyilan8080.gitee.io/loser-blog/js/theme-mode.js'></script>
    <link rel="stylesheet" href='https://lyilan8080.gitee.io/loser-blog/css/frameworks.min.css' />
    <link rel="stylesheet" href='https://lyilan8080.gitee.io/loser-blog/css/github.min.css' />
    <link rel="stylesheet" href='https://lyilan8080.gitee.io/loser-blog/css/github-style.css' />
    <link rel="stylesheet" href='https://lyilan8080.gitee.io/loser-blog/css/light.css' />
    <link rel="stylesheet" href='https://lyilan8080.gitee.io/loser-blog/css/dark.css' />
    <link rel="stylesheet" href='https://lyilan8080.gitee.io/loser-blog/css/syntax.css' />
    <title>如何设计一个类似 mp 的 mongo ORM 框架 - loser博客</title>
    
    <link rel="icon" type="image/x-icon" href='/images/github.png'>
    
    <meta name="theme-color" content="#1e2327">

    
    <meta name="description"
  content="设计思路 使用可序列化的接口函数获取 实体 get 方法对应的字段，通过lambda 的形式将语句转换为 spring 中的 mongoTemplate 支持的语法进行数据的相关操作；并支持使用 mongoTemplate 中的相关接口
" />
<meta name="keywords"
  content='' />
<meta name="robots" content="noodp" />
<link rel="canonical" href="https://lyilan8080.gitee.io/loser-blog/post/mongo/mongo/" />


<meta name="twitter:card" content="summary" />
<meta name="twitter:title" content="如何设计一个类似 mp 的 mongo ORM 框架 - loser博客" />
<meta name="twitter:description"
  content="设计思路 使用可序列化的接口函数获取 实体 get 方法对应的字段，通过lambda 的形式将语句转换为 spring 中的 mongoTemplate 支持的语法进行数据的相关操作；并支持使用 mongoTemplate 中的相关接口
" />
<meta name="twitter:site" content="https://lyilan8080.gitee.io/loser-blog" />
<meta name="twitter:creator" content="" />
<meta name="twitter:image"
  content="https://lyilan8080.gitee.io/loser-blog">


<meta property="og:type" content="article" />
<meta property="og:title" content="如何设计一个类似 mp 的 mongo ORM 框架 - loser博客">
<meta property="og:description"
  content="设计思路 使用可序列化的接口函数获取 实体 get 方法对应的字段，通过lambda 的形式将语句转换为 spring 中的 mongoTemplate 支持的语法进行数据的相关操作；并支持使用 mongoTemplate 中的相关接口
" />
<meta property="og:url" content="https://lyilan8080.gitee.io/loser-blog/post/mongo/mongo/" />
<meta property="og:site_name" content="如何设计一个类似 mp 的 mongo ORM 框架" />
<meta property="og:image"
  content="https://lyilan8080.gitee.io/loser-blog">
<meta property="og:image:width" content="2048">
<meta property="og:image:height" content="1024">

<meta property="article:published_time" content="2024-04-22 00:00:00 &#43;0000 UTC" />










</head>

<body>
  <div style="position: relative">
  <header class="Header js-details-container Details px-3 px-md-4 px-lg-5 flex-wrap flex-md-nowrap open Details--on">
    <div class="Header-item mobile-none" style="margin-top: -4px; margin-bottom: -4px;">
      <a class="Header-link" href="https://lyilan8080.gitee.io/loser-blog">
        <svg class="octicon" height="32" viewBox="0 0 16 16" version="1.1" width="32">
          <path fill-rule="evenodd"
            d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z">
          </path>
        </svg>
      </a>
    </div>
    <div class="Header-item d-md-none">
      <button class="Header-link btn-link js-details-target" type="button"
        onclick="document.querySelector('#header-search').style.display = document.querySelector('#header-search').style.display == 'none'? 'block': 'none'">
        <svg height="24" class="octicon octicon-three-bars" viewBox="0 0 16 16" version="1.1" width="24">
          <path fill-rule="evenodd"
            d="M1 2.75A.75.75 0 011.75 2h12.5a.75.75 0 110 1.5H1.75A.75.75 0 011 2.75zm0 5A.75.75 0 011.75 7h12.5a.75.75 0 110 1.5H1.75A.75.75 0 011 7.75zM1.75 12a.75.75 0 100 1.5h12.5a.75.75 0 100-1.5H1.75z">
          </path>
        </svg>
      </button>
    </div>
    <div style="display: none;" id="header-search"
      class="Header-item Header-item--full flex-column flex-md-row width-full flex-order-2 flex-md-order-none mr-0 mr-md-3 mt-3 mt-md-0 Details-content--hidden-not-important d-md-flex">
      <div
        class="Header-search header-search flex-auto js-site-search position-relative flex-self-stretch flex-md-self-auto mb-3 mb-md-0 mr-0 mr-md-3 scoped-search site-scoped-search js-jump-to">












      </div>
    </div>

    <div class="Header-item Header-item--full flex-justify-center d-md-none position-relative">
      <a class="Header-link " href="https://lyilan8080.gitee.io/loser-blog">
        <svg class="octicon octicon-mark-github v-align-middle" height="32" viewBox="0 0 16 16" version="1.1"
          width="32">
          <path fill-rule="evenodd"
            d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z">
          </path>
        </svg>
      </a>
    </div>
    <div class="Header-item" style="margin-right: 0;">
      <a href="javascript:void(0)" class="Header-link no-select" onclick="switchTheme()">
        <svg style="fill: var(--color-profile-color-modes-toggle-moon);" class="no-select" viewBox="0 0 16 16"
          version="1.1" width="16" height="16">
          <path fill-rule="evenodd" clip-rule="evenodd"
            d="M4.52208 7.71754C7.5782 7.71754 10.0557 5.24006 10.0557 2.18394C10.0557 1.93498 10.0392 1.68986 10.0074 1.44961C9.95801 1.07727 10.3495 0.771159 10.6474 0.99992C12.1153 2.12716 13.0615 3.89999 13.0615 5.89383C13.0615 9.29958 10.3006 12.0605 6.89485 12.0605C3.95334 12.0605 1.49286 10.001 0.876728 7.24527C0.794841 6.87902 1.23668 6.65289 1.55321 6.85451C2.41106 7.40095 3.4296 7.71754 4.52208 7.71754Z">
          </path>
        </svg>
      </a>
    </div>
  </header>
</div>
  
<div>
  <main>
    <div class="gisthead pagehead bg-gray-light pb-0 pt-3 mb-4">
      <div class="px-0">
        <div class="mb-3 d-flex px-3 px-md-3 px-lg-5">
          <div class="flex-auto min-width-0 width-fit mr-3">
            <div class="d-flex">
              <div class="d-none d-md-block">
                <a class="avatar mr-2 flex-shrink-0" href="https://lyilan8080.gitee.io/loser-blog">
                  <img class=" avatar-user"
                    src="https://lyilan8080.gitee.io/loser-blog/images/avatar.png"
                    width="32" height="32"></a>
              </div>
              <div class="d-flex flex-column">
                <h1 class="break-word f3 text-normal mb-md-0 mb-1">
                  <span class="author">
                    <a href="https://lyilan8080.gitee.io/loser-blog">Loser</a></span><span
                    class="path-divider">/</span><strong class="css-truncate-target mr-1" style="max-width: 410px"><a
                      href="https://lyilan8080.gitee.io/loser-blog/post/mongo/mongo/">如何设计一个类似 mp 的 mongo ORM 框架</a></strong>
                </h1>
                <div class="note m-0">
                  创建于 <relative-time datetime="Mon, 22 Apr 2024 00:00:00 &#43;0000"
                    class="no-wrap">
                    Mon, 22 Apr 2024 00:00:00 &#43;0000</relative-time>

                  
                  <span class="file-info-divider"></span>
                  修改于 <relative-time datetime="Mon, 22 Apr 2024 14:17:56 &#43;0800"
                    class="no-wrap">
                    Mon, 22 Apr 2024 14:17:56 &#43;0800</relative-time>
                  
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="container-lg px-3 new-discussion-timeline">
      <div class="repository-content gist-content">
        <div>
          <div class="js-gist-file-update-container js-task-list-container file-box">
            <div id="file-pytest" class="file my-2">
              <div id="post-header" class="file-header d-flex flex-md-items-center flex-items-start sticky-header" style="z-index: 2">
                <div class="file-info d-flex flex-md-items-center flex-items-start flex-order-1 flex-auto">
                  <div class="text-mono f6 flex-auto pr-3 flex-order-2 flex-md-order-1 mt-2 mt-md-0">
                    
                    <summary id="toc-toggle" onclick="clickToc()" class="btn btn-octicon m-0 mr-2 p-2">
                      <svg aria-hidden="true" viewBox="0 0 16 16" height="16" width="16" class="octicon octicon-list-unordered">
                        <path fill-rule="evenodd" d="M2 4a1 1 0 100-2 1 1 0 000 2zm3.75-1.5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zm0 5a.75.75 0 000 1.5h8.5a.75.75 0 000-1.5h-8.5zM3 8a1 1 0 11-2 0 1 1 0 012 0zm-1 6a1 1 0 100-2 1 1 0 000 2z"></path>
                      </svg>
                    </summary>
                    <details-menu class="SelectMenu" id="toc-details" style="display: none;">
                      <div class="SelectMenu-modal rounded-3 mt-1" style="max-height: 340px;">
                        <div class="SelectMenu-list SelectMenu-list--borderless p-2" style="overscroll-behavior: contain;" id="toc-list">
                        </div>
                      </div>
                    </details-menu>
                      243 Words
                    

                  </div>
                  <div class="file-actions flex-order-2 pt-0">
                    
                    
                    <a class="muted-link mr-3" href="/tags/mongo">
                      <svg class="octicon octicon-tag" viewBox="0 0 16 16" version="1.1" width="16" height="16">
                        <path fill-rule="evenodd"
                          d="M2.5 7.775V2.75a.25.25 0 01.25-.25h5.025a.25.25 0 01.177.073l6.25 6.25a.25.25 0 010 .354l-5.025 5.025a.25.25 0 01-.354 0l-6.25-6.25a.25.25 0 01-.073-.177zm-1.5 0V2.75C1 1.784 1.784 1 2.75 1h5.025c.464 0 .91.184 1.238.513l6.25 6.25a1.75 1.75 0 010 2.474l-5.026 5.026a1.75 1.75 0 01-2.474 0l-6.25-6.25A1.75 1.75 0 011 7.775zM6 5a1 1 0 100 2 1 1 0 000-2z">
                        </path>
                      </svg>
                      mongo
                    </a>
                    
                    
                  </div>
                </div>
              </div>


              <div class="Box-body px-5 pb-5" style="z-index: 1">
                <article class="markdown-body entry-content container-lg"><h1 id="设计思路">设计思路</h1>
<p>使用可序列化的接口函数获取 实体 get 方法对应的字段，通过lambda 的形式将语句转换为 spring 中的 mongoTemplate 支持的语法进行数据的相关操作；并支持使用 mongoTemplate 中的相关接口</p>
<h4 id="使用步骤">使用步骤</h4>
<ol>
<li>
<p>添加依赖</p>
<p><img src="../../../static/mongo/no01.png" alt="no01.png"></p>
</li>
<li>
<p>添加mongo对应的实体</p>
<p><img src="../../../static/mongo/no02.png" alt="no02.png"></p>
</li>
<li>
<p>添加mongo对应的服务接口并继承依赖中的 com.loser.core.sdk.MogoService</p>
<p><img src="../../../static/mongo/no03.png" alt="no03.png"></p>
</li>
<li>
<p>添加mongo对应的服务接口实现类并继承依赖中的 com.loser.core.impl.MogoServiceImpl</p>
<p><img src="../../../static/mongo/no04.png" alt="no04.png"></p>
</li>
<li>
<p>业务中导入依赖 并使用内置的 api 进行相关的 crud 查询</p>
<p><img src="../../../static/mongo/no05.png" alt="no05.png"></p>
</li>
</ol>
<h4 id="核心功能点">核心功能点</h4>
<ol>
<li>
<p>参考 mp 使用可序列化的接口函数获取字段</p>
<p><img src="../../../static/mongo/no06.png" alt="no06.png"></p>
</li>
<li>
<p>内置常用 crud 接口</p>
<p><img src="../../../static/mongo/no07.png" alt="no07.png"></p>
</li>
<li>
<p>核心条件包裹对象 封装参数需要使用的相关参数</p>
<p><img src="../../../static/mongo/no08.png" alt="no08.png"></p>
</li>
<li>
<p>参数构建工具 使用参数包裹对象，将参数转变为 mongoTemplate 支持的语法</p>
<p><img src="../../../static/mongo/no09.png" alt="no09.png"></p>
</li>
</ol></article>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </main>
</div>
<script type="application/javascript" src='https://lyilan8080.gitee.io/loser-blog/js/toc.js'></script>
<link rel="stylesheet" href='https://lyilan8080.gitee.io/loser-blog/css/toc.css' />


<link rel="stylesheet" href='https://lyilan8080.gitee.io/loser-blog/css/gitalk.css'>
<script src='https://lyilan8080.gitee.io/loser-blog/js/gitalk.min.js'></script>
<script>
  const gitalk = new Gitalk({
    clientID: '',
    clientSecret: '',
    repo: '',
    owner: '',
    admin: [''],
    id: eval( null ), 
    distractionFreeMode: false 
  });
  (function() {
    gitalk.render('gitalk-container');
  })();
</script>


  <div class="footer container-xl width-full p-responsive">
  <div
    class="position-relative d-flex flex-row-reverse flex-lg-row flex-wrap flex-lg-nowrap flex-justify-center flex-lg-justify-between flex-sm-items-center pt-6 pb-2 mt-6 f6 text-gray border-top border-gray-light ">
    <a aria-label="Homepage" title="GitHub" class="footer-octicon d-none d-lg-block mr-lg-4" href="https://lyilan8080.gitee.io/loser-blog">
      <svg height="24" class="octicon octicon-mark-github" viewBox="0 0 16 16" version="1.1" width="24">
        <path fill-rule="evenodd"
          d="M8 0C3.58 0 0 3.58 0 8c0 3.54 2.29 6.53 5.47 7.59.4.07.55-.17.55-.38 0-.19-.01-.82-.01-1.49-2.01.37-2.53-.49-2.69-.94-.09-.23-.48-.94-.82-1.13-.28-.15-.68-.52-.01-.53.63-.01 1.08.58 1.23.82.72 1.21 1.87.87 2.33.66.07-.52.28-.87.51-1.07-1.78-.2-3.64-.89-3.64-3.95 0-.87.31-1.59.82-2.15-.08-.2-.36-1.02.08-2.12 0 0 .67-.21 2.2.82.64-.18 1.32-.27 2-.27.68 0 1.36.09 2 .27 1.53-1.04 2.2-.82 2.2-.82.44 1.1.16 1.92.08 2.12.51.56.82 1.27.82 2.15 0 3.07-1.87 3.75-3.65 3.95.29.25.54.73.54 1.48 0 1.07-.01 1.93-.01 2.2 0 .21.15.46.55.38A8.013 8.013 0 0016 8c0-4.42-3.58-8-8-8z">
        </path>
      </svg>
    </a>
    <ul class="list-style-none d-flex flex-wrap col-12 flex-justify-center flex-lg-justify-between mb-2 mb-lg-0">
      
      <li class="mr-3 mr-lg-0">Theme by github-style</a></li>
      
    </ul>
  </div>
  <div class="d-flex flex-justify-center pb-6">
    <span class="f6 text-gray-light"></span>
  </div>


</div>
</body>

<script type="application/javascript" src="https://lyilan8080.gitee.io/loser-blog/js/github-style.js"></script>




</html>